//
// Created by YeMingMing on 2024-03-07.
//

// 链表逆序
#include "../linklist.h"
#include "stdlib.h"

LinkList reverse(LinkList L) {
    LNode *result = (LNode *) malloc(sizeof (LNode));
    result->next = NULL;
    LNode *p = L->next, *q;
    while (p != NULL){
        q = p;
        p = p->next;
        q->next = result->next;
        result->next = q;
    }
    return result;
}

int main() {
    LinkList L;
    InitList(&L);
    for (int i = 0; i < 10; ++i) {
        InsertElem(L,i);
    }
    PrintList(L);
    PrintList(reverse(L));


    return 0;
}
